package cn.ydt.ydt.community.webapi.controller;

import cn.ydt.ydt.common.resful.JsonResult;
import cn.ydt.ydt.community.service.IOutService;
import cn.ydt.ydt.pojo.community.dto.AddOutDTO;
import cn.ydt.ydt.pojo.community.model.OutRequest;
import cn.ydt.ydt.pojo.community.vo.OutPeopleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "申请外出模块")
@RestController
@RequestMapping(value = "/out", produces = "application/json; charset=utf-8")
public class OutController {
    @Autowired
    IOutService iOutService;

    /**
     * 添加外出人员申请
     * @param addOutDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "人员外出申请")
    public JsonResult<Void> addUserOut(@Validated @RequestBody AddOutDTO addOutDTO){
        iOutService.addOutApply(addOutDTO);
        return JsonResult.ok();
    }

    /**
     * 根据UserId查询个人外出记录
     * @return
     */
    @GetMapping("/personalOut")
    @ApiOperation(value = "个人外出记录查询")
    public JsonResult<List<OutPeopleVO>> selectPersonalOut() {
        List<OutPeopleVO> outPeopleVO = iOutService.selectPersonalOut();
        return JsonResult.ok(outPeopleVO,"查询成功！");
    }

    /**
     * 查询外出申请待审核列表
     * @return
     */
    @GetMapping("/outRequest")
    @ApiOperation(value = "外出申请待审核列表")
    public JsonResult<List<OutPeopleVO>> selectOutRequestIsCheck() {
        List<OutPeopleVO> outPeopleVO = iOutService.selectOutRequestIsCheck();
        return JsonResult.ok(outPeopleVO,"查询成功！");
    }

    /**
     * 查询外出人员列表
     * @return
     */
    @GetMapping("/outList")
    @ApiOperation(value = "外出人员列表")
    public JsonResult<List<OutPeopleVO>> selectOutPeopleList() {
        List<OutPeopleVO> outPeopleVO = iOutService.selectOutPeopleList();
        return JsonResult.ok(outPeopleVO,"查询成功！");
    }

    /**
     * 查询已审核列表
     */
    @GetMapping("/is/check")
    @ApiOperation(value = "已审核人员列表")
    public JsonResult<List<OutRequest>> getIsCheckList(){
        List<OutRequest> list = iOutService.getIsCheckList();
        return JsonResult.ok(list);
    }

    /**
     * 修改为已审核
     */
    @GetMapping("/check/true/{outId}")
    @ApiOperation(value = "审核外出通过")
    public JsonResult<Void> IsCheckTrue(@PathVariable Long outId){
        iOutService.IsCheckTrue(outId);
        return JsonResult.ok("审核通过");
    }

    /**
     * 修改为已驳回
     */
    @GetMapping("/check/false/{outId}")
    @ApiOperation(value = "审核外出驳回")
    public JsonResult<Void> IsCheckFalse(@PathVariable Long outId){
        iOutService.IsCheckFalse(outId);
        return JsonResult.ok("申请已驳回");
    }


}